package com.yikes.srb.controller.web;

import com.yikes.srb.common.result.PageResult;
import com.yikes.srb.common.result.Result;
import com.yikes.srb.leadingModle.form.userLoginRecord.UserLoginRecordAddForm;
import com.yikes.srb.leadingModle.form.userLoginRecord.UserLoginRecordEditForm;
import com.yikes.srb.leadingModle.form.userLoginRecord.UserLoginRecordQuery;
import com.yikes.srb.leadingModle.vo.UserLoginRecordVO;
import com.yikes.srb.service.UserLoginRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户登录记录表 前端控制器
 * </p>
 *
 * @author guanrong.yin
 * @since 2024-12-03
 */
@RequiredArgsConstructor
@Tag(name = "UserLoginRecordController", description = "用户登录记录表")
@RestController
@RequestMapping("/admin/user_login_record")
public class UserLoginRecordController {

    private final UserLoginRecordService service;

    @Operation(description = "分页查询")
    @GetMapping("/list_page")
    public Result<PageResult<UserLoginRecordVO>> listPage(UserLoginRecordQuery query) {

        return Result.ok(service.listPage(query));
    }

    @Operation(description = "根据id查询单条信息")
    @GetMapping("/info/{id}")
    public Result<UserLoginRecordVO> infoId(@PathVariable("id") Long id) {

        return Result.ok(service.infoId(id));
    }

    @Operation(description = "新增")
    @PostMapping("/create")
    public Result create(@Valid @RequestBody UserLoginRecordAddForm form) {

        service.create(form);
        return Result.ok();
    }

    @Operation(description = "编辑")
    @PutMapping("/edit")
    public Result edit(@Valid @RequestBody UserLoginRecordEditForm form) {

        service.edit(form);
        return Result.ok();
    }

    @Operation(description = "删除")
    @DeleteMapping("/del/{id}")
    public Result del(@PathVariable("id") Long id) {

        service.del(id);
        return Result.ok();
    }

    @Operation(description = "获取会员登录日志列表")
    @GetMapping("/listTop50/{userId}")
    public Result listTop50(
            @Schema(description = "用户id") @PathVariable Long userId) {

        List<UserLoginRecordVO> userLoginRecordList = service.listTop50(userId);
        return Result.ok(userLoginRecordList);
    }

}
